package org.jeecg.modules.parameter.biz.controlltr;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.modules.parameter.api.dto.platform.SimPlatformDto;
import org.jeecg.modules.parameter.api.dto.transfer.SimTransferDto;
import org.jeecg.modules.parameter.api.entity.SimPlatform;
import org.jeecg.modules.parameter.api.entity.SimTransfer;
import org.jeecg.modules.parameter.api.vo.platform.SimPlatformVo;
import org.jeecg.modules.parameter.api.vo.transfer.SimTransferVo;
import org.jeecg.modules.parameter.biz.service.SimStationPlatformService;
import org.jeecg.modules.parameter.biz.service.SimStationTransferService;
import org.jeecg.modules.parameter.common.api.dto.PatchPO;
import org.jeecg.modules.parameter.common.utils.oConvertUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author lsy
 * @date 2024/09/17
 */
@Api(tags = "参数管理-车站-换乘通道管理")
@RestController
@RequestMapping(value = {"/stationTransfer"}, produces = {"application/json; charset=utf-8"})
@Slf4j
public class SimStationTransferController extends JeecgController<SimPlatform, SimStationPlatformService> {
    @Resource
    private SimStationTransferService  transferService;

    @ApiOperation(value = "按车站ID查询换乘通道信息", notes = "按车站ID查询换乘通道信息")
    @PostMapping(value = "/getTransferBySataId")
    public Result<List<SimTransferVo>> getTransferBySataId(@RequestParam(name = "stationId", required = true) String id) {
        List<SimTransferVo> simTransferVo = oConvertUtils.entityListToModelList(transferService.getTransferBySataId(id), SimTransferVo.class);
        return Result.ok(simTransferVo);
    }

    @ApiOperation(value = "按ID删除换乘通道信息", notes = "按ID删除换乘通道信息")
    @DeleteMapping(value = "/delTransfer")
    public Result<String> delTransfer(@RequestParam(name = "id", required = true) String id) {
        transferService.removeById(id);
        return Result.ok("删除成功");
    }

    @ApiOperation(value = "按ID查询换乘通道信息", notes = "按ID查询换乘通道信息")
    @PostMapping(value = "/queryTransferById")
    public Result<SimTransferVo> queryTransferById(@RequestParam(name = "id", required = true) String id) {
        return Result.ok(oConvertUtils.entityToModel(transferService.getById(id), SimTransferVo.class));
    }

    @ApiOperation(value = "添加车站换乘通道信息", notes = "添加车站换乘通道信息")
    @PostMapping(value = "/addTransfer")
    public Result<String> addTransfer(@RequestBody SimTransferDto simTransferDto) {
        SimTransfer simTransfer = oConvertUtils.entityToModel( simTransferDto, SimTransfer.class);
        transferService.save(simTransfer);
        return Result.ok("保存成功");
    }


    @ApiOperation(value = "修改车站换乘通道信息", notes = "修改车站换乘通道信息")
    @PutMapping(value = "/updateTransfer")
    public Result<String> updateTransfer(@RequestBody PatchPO patchPO) {
        transferService.updatePatch(patchPO);
        return Result.OK("更新成功!");
    }

}
